package bd1.obli2012.extapp;


import bd1.obli2012.framework.QueryCriteria;
import bd1.obli2012.framework.definicion.Columna;
import java.util.List;
import javax.swing.DefaultComboBoxModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author favio.ortelli/guillermo.nasi
 */
public class PanelFiltro extends javax.swing.JPanel {

    private String[] operadores = {"=", ">", "<", ">=", "<=", "like"};

    /**
     * Creates new form PanelFiltro
     */
    public PanelFiltro(List<Columna> columnas) {
        
        initComponents();
        cmbOperador.setModel(new DefaultComboBoxModel(operadores));
        cmbColumna.setModel(new DefaultComboBoxModel(columnas.toArray()));
        
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cmbColumna = new javax.swing.JComboBox();
        cmbOperador = new javax.swing.JComboBox();
        valorCriteria = new javax.swing.JTextField();

        cmbColumna.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        cmbOperador.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(cmbColumna, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmbOperador, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(valorCriteria, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmbColumna, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbOperador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(valorCriteria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cmbColumna;
    private javax.swing.JComboBox cmbOperador;
    private javax.swing.JTextField valorCriteria;
    // End of variables declaration//GEN-END:variables

    /**
     * Obtiene la QueryCriteria que se formo en el panel
     * @return 
     */
    public QueryCriteria getQueryCriteria(){
        QueryCriteria salida = null;
        if(!"".equals(this.valorCriteria.getText().trim())) {
            salida = new QueryCriteria(
                    this.cmbColumna.getSelectedItem().toString(), 
                    this.cmbOperador.getSelectedItem().toString(), 
                    this.valorCriteria.getText().trim());
        }
        return salida;
    }
}
